package com.newdjk.newdoctor.ui;

import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
import com.newdjk.newdoctor.R;
import com.newdjk.newdoctor.utils.Contants;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author EDZ
 */ /*
 *  @项目名：  Doctor
 *  @包名：    com.newdjk.doctor.ui
 *  @文件名:   AdsDialog
 *  @创建者:   huhai
 *  @创建时间:  2019/3/12 10:43
 *  @描述：广告对话框
 */
public class AdsDialogActivity extends Activity implements View.OnClickListener {


    @BindView(R.id.image)
    ImageView image;
    @BindView(R.id.im_cancel)
    ImageView imCancel;
    @BindView(R.id.lv_root)
    RelativeLayout lvRoot;
    String url = "";

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ads_dialog);
        ButterKnife.bind(this);
        initdata();
        url = getIntent().getStringExtra("linkurl");
        initlistener();
    }

    private void initlistener() {

        imCancel.setOnClickListener(this);
        image.setOnClickListener(this);
    }

    private void initdata() {


        Glide.with(AdsDialogActivity.this) // could be an issue!
                .load(url)
                .error(R.drawable.new_nopic)
                .into(new SimpleTarget<Drawable>() {
                    @Override
                    public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
                        image.setImageDrawable(resource);
                        lvRoot.setVisibility(View.VISIBLE);
                    }
                });
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.im_cancel:
                finish();
                break;
            case R.id.image:
                // ToastUtil.setToast("点击了广告");
                if (!TextUtils.isEmpty(url)) {
                    if (url.startsWith("http")) {
                        Intent intent = new Intent(this, WebViewActivity.class);
                        intent.putExtra("url", url);
                        intent.putExtra(Contants.TYPE, 31);
                        startActivity(intent);
                    } else {
                        Intent intent = new Intent(this, WebViewActivity.class);
                        intent.putExtra("innerLink", url);
                        intent.putExtra(Contants.TYPE, 21);
                        startActivity(intent);
                    }
                }
                break;
        }
    }
}

